<? 
		include_once('conn.php');
		
		if($_REQUEST["txtname"] != "") {
		
		$name = strtoupper($_GET["txtname"]);
		mysql_db_query("dbStudents","insert into tblstudents(stud_name,stud_course) values ('$name','$_GET[cbocourse]')",$conn);
			
			header("Location:index.php");
		}	
		
		
		//=====================================================================================
		
			 if($_POST["txtCtr"] =="update") {
				
				echo("<br><br><br>");
				
				echo("<form name='frm1' method='post' action='update.php' onsubmit='return AskQ()'>");
			
			if($_POST['check'] <> "") {
			
				foreach($_POST['check'] as $ctrl) {
					
$sql=mysql_db_query("dbStudents","SELECT `tblstudents`.`stud_control`, `tblstudents`.`stud_name`,`tblstudents`.`stud_course`, `tblcourse`.`course_control`, `tblcourse`.`course_desc`
FROM `tblstudents`LEFT JOIN `tblcourse` ON `tblstudents`.`stud_course` = `tblcourse`.`course_control` where stud_control=$ctrl order by `stud_name`",$conn); 
$field = mysql_fetch_array($sql);

$cf = $field['course_control'];

					echo("<center>
					<input type='hidden' name='txtcontrol[]' value='$field[stud_control]'>
					<input type='input' name='txtnameEdit[]' value='$field[stud_name]'>");
					
			$sql1 = mysql_db_query("dbStudents","select * from tblcourse where course_control <> $cf order by course_desc",$conn);
			
					echo("<select name='cbocourse[]' style='border-width:medium'/>");
				
						while($field1 = mysql_fetch_array($sql1)) {
							echo("<option value='$field1[course_control]' selected='selected'>$field1[course_desc]</option>");
						}
						
					echo("<option value='$field[course_control]' selected='selected'>$field[course_desc]</option>");
						
					echo("</center>");
					echo("</select>");

				}	
			
			}
					echo("<br><br><input type='submit' name='cmdupdate' value='Update'>");
					echo("</form><br>");
				
					
			}else {
		
				foreach($_POST["check"] as $ctrl)
				{	
					mysql_db_query("dbStudents","delete from tblstudents where stud_control = $ctrl",$conn);
					header("Location:index.php");
				}
			
			
			}
	

?>


<script language="javascript">

	function AskQ() {
		if(confirm('Are you sure to update this record?')==true) {
			return true;
		}else {
			return false;
		}
	}

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
	
<body>
</body>
</html>
